package com.rrd.hive.udf;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

import com.rrd.hive.util.PIDValidator;

public class PIDValidateUDF extends UDF{

	public Text evaluate(String str) {
		Text text = new Text("0");
		if(str==null || str.length()==0){
			return text;
		}
		if(PIDValidator.isValidIDCard(str)){
			text.set("1");
		}
		return text;
		
	}
	public static void main(String[] args) {
		String str="某某小区，sdf2单元201";
		System.out.println(str);
		 Pattern p = Pattern.compile(".*[0-9]+(楼|号楼|院)(.*)");
	     Matcher m = p.matcher(str);
	     
	     if(m.find()){
	    	 System.out.println(m.group(2));
	    	str= str.replace(m.group(2), "****");
	     }
	      
		System.out.println(str);
	}
}
